package de.mfits.fireflyplayer.importer;

import java.net.URL;

import net.firefly.client.controller.listeners.SongListLoadProgressListener;
import net.firefly.client.controller.request.IRequestManager;
import net.firefly.client.controller.request.RequestManagerFactory;
import net.firefly.client.http.protocol.Protocol;
import net.firefly.client.model.data.Database;
import net.firefly.client.model.data.list.SongList;
import net.firefly.client.tools.FireflyClientException;

public class ServerConnection {
  private final String host;
  private final int port;
  private final String proxyHost;
  private final String proxyPort;
  private final String password;

  private final IRequestManager requestManager = RequestManagerFactory
      .getMainRequestManagerInstance(Protocol.RSP);

  public ServerConnection(String host, int port) {
    this(host, port, null, null, null);
  }

  public ServerConnection(String host, int port, String proxyHost, String proxyPort, String password) {
    this.host = host;
    this.port = port;
    this.proxyHost = proxyHost;
    this.proxyPort = proxyPort;
    this.password = password;
  }

  public Database getDatabase() throws FireflyClientException {
    return requestManager.getDatabase(host, port, proxyHost, proxyPort, password);
  }

  public SongList getSongList() throws FireflyClientException {
    return requestManager.getSongList(host, port, proxyHost, proxyPort, password);
  }

  public SongList getSongList(SongListLoadProgressListener listener) throws FireflyClientException {
    return requestManager.getSongList(host, port, proxyHost, proxyPort, password, listener);
  }

  public URL getSongStreamUrl(int id) throws FireflyClientException {
    return requestManager.getSongStreamURL(host, port, id);
  }
}
